package array.practice;

import java.util.Arrays;

/**
 * 反转数组，要求空间复杂度为 1
 * @param <T>
 */
public class ReverseArray<T> {

    public static void main(String[] args) {
        ReverseArray<Integer> reverseArray = new ReverseArray<>();
        Integer[] input={4,5,3,6,7,9,1};
        reverseArray.reverse(input);
        System.out.println(Arrays.toString(input));
    }

    public void reverse(T[] array) {
        T temp;
        for (int i = 0,j=array.length-1; i <j; i++,j--) {
            temp=array[i];
            array[i]=array[j];
            array[j]=temp;
        }
    }
}
